/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * V1ConsBusqSimple.java
 *
 * Created on 14-may-2012, 12:39:47
 */
package practtica4;

import BBDD.GestorBBDD;
import DTO.Acontecimiento;
import DTO.Colectivo;
import DTO.Documento;
import DTO.Personaje;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author usuario_local
 */
public class V1ConsBusqSimple extends javax.swing.JFrame {

    /** Creates new form V1ConsBusqSimple */
       GestorBBDD gestor=new GestorBBDD();
    public V1ConsBusqSimple() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        botonAceptar = new javax.swing.JButton();
        botonTextoaBuscar = new javax.swing.JTextField();
        labelTextoBusq = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        botonAceptar.setText("Aceptar");
        botonAceptar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                botonAceptarMouseClicked(evt);
            }
        });

        labelTextoBusq.setText("Texto a buscar");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(86, 86, 86)
                .addComponent(labelTextoBusq)
                .addGap(40, 40, 40)
                .addComponent(botonTextoaBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(37, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botonAceptar)
                .addGap(74, 74, 74))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(89, 89, 89)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelTextoBusq)
                    .addComponent(botonTextoaBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 125, Short.MAX_VALUE)
                .addComponent(botonAceptar)
                .addGap(56, 56, 56))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonAceptarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botonAceptarMouseClicked
        // TODO add your handling code here:
        String buscar= this.botonTextoaBuscar.getText();
        int i=0;
        String cosa="";
        ArrayList<Acontecimiento> resAcon= new ArrayList<Acontecimiento>();
        ArrayList<Colectivo> resColect= new ArrayList<Colectivo>();
        ArrayList<Personaje> resPers= new ArrayList<Personaje>();
        ArrayList<Documento> resDoc= new ArrayList<Documento>();
        ArrayList<String> cosas= new ArrayList<String>();
        
        while(i<buscar.length()){
            if(buscar.charAt(i)==','){ //cosa ya es algo, lo busco:
                cosas.add(cosa);               
            }
            else cosa+=buscar.charAt(i);
            i++;
        }
        if(!cosa.equals(""))cosas.add(cosa); 
        try {
            resAcon = gestor.busquedaSimpleA(cosas);
            resColect = gestor.busquedaSimpleC(cosas);
            resPers = gestor.busquedaSimpleP(cosas);
            resDoc = gestor.busquedaSimpleD(cosas,resAcon,resColect,resPers);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(V1ConsBusqSimple.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(V1ConsBusqSimple.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        V1BusqSimpleEligeResult v1res= new V1BusqSimpleEligeResult(buscar,resAcon,resColect,resPers,resDoc);
        v1res.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_botonAceptarMouseClicked

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JTextField botonTextoaBuscar;
    private javax.swing.JLabel labelTextoBusq;
    // End of variables declaration//GEN-END:variables
}
